﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for ConnectSQL
/// </summary>
public class ConnectData
{
    const string INSTANCE = "ANH-PC\\SQLEXPRESS";
    const string USERNAME = "sa";
    const string PASSWORD = "sa";
    const string DATABASE = "benhvien";
    SqlConnection conn;
    public ConnectData()
	{
        try
        {
            conn = new SqlConnection();
            conn.ConnectionString = string.Format(@"Data Source={0};" + "Initial Catalog={1};" + "User Id={2};" + "Password={3}; Integrated Security=True; ", INSTANCE, DATABASE, USERNAME, PASSWORD);
            conn.Open();
        }
        catch (Exception e)
        {
            ShowText.show("loi");
        }
    }
    public SqlConnection getConnection()
    {
        return conn;
    }
    public void closeConnect(){
        conn.Close();
    }
    public SqlDataReader dataReader(string sql)
    {
        SqlCommand  result = new SqlCommand(sql, conn);
        return result.ExecuteReader();
    }
    public SqlDataAdapter dataAdapter(string sql)
    {
        SqlDataAdapter result = new SqlDataAdapter(sql, conn);
        return result;
    }
}